import axios from "axios";
import qs from 'qs';

// 创建一个axios对象
let http = axios.create({
    // 根路径
    baseURL: 'http://localhost:8090/',
    // 连接超时时间
    timeout: 1000000000,
    // 是否携带凭证
    //  withCredentials: true,
});

http.interceptors.request.use(config=>{
    // 请求方式是post
    if(config.method == "post" || config.method == "POST"){
        console.log("1");
        config.data = qs.stringify(config.data);
        config.headers['content-Type'] = 'application/x-www-form-urlencoded';
    }
    // 获取token
    let token = sessionStorage.getItem('token');
    // 请求携带token值
    if(token!=undefined){
        config.headers.token = token;
    }

    return config;
});

http.interceptors.response.use(response=>{

    return response.data;
});

export default http

